package com.leapp.sk.ui.activity.classs

import android.content.Intent
import android.os.Bundle
import cc.vv.lkbasecomponent.http.LKHttp
import cc.vv.lkbasecomponent.http.lib.setting.Settings
import cc.vv.lklibrary.http.base.okhttpfactory.plugins.httpplugin.MediaTypeWrap
import com.example.baselibrary.util.LKToastUtil
import com.example.mvp.activity.BaseActivityMVP
import com.example.mvp.binder.BaseDataBinder
import com.leapp.sk.R
import com.leapp.sk.app.CLASS_DETIAL_MODIFY
import com.leapp.sk.bean.request.classs.ModifyClassNameRequestEntity
import com.leapp.sk.bean.response.BaseResponseDataEntity
import com.leapp.sk.binder.BaseBinder
import com.leapp.sk.inter.TopBarRightClickInterface
import com.example.util.finallist.*
import com.leapp.sk.viewdelegate.classs.ModifyGroupNameDelegate

/**
 * 修改群昵称
 * @author  chaohaipeng  on 2018/7/30.
 */
class ModifyGroupNameActiity:BaseActivityMVP<ModifyGroupNameDelegate>(), TopBarRightClickInterface {

    var classPersonnelId:String?=""
    override fun searchData() {
        httpNameModify()
    }

    override fun initDate() {
        val groupName = intent?.getStringExtra(MY_GROUP_NICK)
        classPersonnelId = intent?.getStringExtra(CLASS_PERSONNELID)
        viewDelegate.initEditText(groupName,this)

    }

    override fun initView(p0: Bundle?) {
        viewDelegate.setTitle(resources.getString(R.string.string_class_my_group_nick))

    }

    override fun bindEvenListener() {
    }

    override fun getDelegateClass(): Class<ModifyGroupNameDelegate> {
        return ModifyGroupNameDelegate::class.java
    }

    override fun getDataBinder(): BaseDataBinder<*, *> {
        return BaseBinder()
    }
    /**
     * 班级名称修改
     */
    private fun httpNameModify() {
        if (classPersonnelId==null){
            return
        }
        val modifyClassNameRequestEntity = ModifyClassNameRequestEntity()
        modifyClassNameRequestEntity.id=classPersonnelId!!
        modifyClassNameRequestEntity.nickName=viewDelegate.getSubmitContent()
        LKHttp.post(CLASS_DETIAL_MODIFY, modifyClassNameRequestEntity, BaseResponseDataEntity::class.java, object : BaseCallBack<BaseResponseDataEntity>(this) {
            override fun onSuccess(url: String?, resultText: String?, obj: BaseResponseDataEntity?) {
                super.onSuccess(url, resultText, obj)
                if (obj?.code == SKCODE_200) {
                    val intent: Intent = Intent(this@ModifyGroupNameActiity, ClassDetialActivity::class.java)
                    intent.putExtra(MY_GROUP_NICK,viewDelegate.getSubmitContent())
                    this@ModifyGroupNameActiity.setResult(CODE_206,intent)
                    this@ModifyGroupNameActiity.finish()
                }else{
                    LKToastUtil.showToastShort(obj?.message)
                }
            }
            override fun onFailure(url: String?, isLoading: Boolean, exceptionStr: String?) {
                super.onFailure(url, isLoading, exceptionStr)
                LKToastUtil.showToastShort(resources.getString(R.string.app_net_erro))
            }
        }
                , true, Settings(MediaTypeWrap.MEDIA_TYPE_FORM))

    }
}